<!--题目类别菜单展式-->
<template>
  <div>
      <el-input placeholder="输入关键字进行过滤" v-model="filterText">
      </el-input>
      <el-tree
        class="filter-tree"
        :data="data"
        :props="defaultProps"
        default-expand-all
        :filter-node-method="filterNode"
        ref="tree"
      >
      </el-tree>
  </div>
</template>
<style>
.left {
  width: 200px;
  margin-left: 20px;
  display: inline-block;
}
</style>
<script>
export default {
  data() {
    return {
      filterText: "",
      data: [],
      defaultProps: {
        children: "menus",
        label: "name",
      },
    };
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },

  created() {
    this.findAll();
  },
  methods: {
    findAll() {
      //console.log("你好");
      //发送axios拿取菜单
      this.$axios
        .get("/api/examMenu/findAll")
        .then((res) => {
        //   console.log(res);
          //赋值给data
          this.data = res.data.data;
        //   console.log(this.data);
        })
        .catch(() => {});
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
  },
};
</script>